package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.New.NewsDetailsActivity;
import com.example.myapplication.Outpatientappointment.ModifyclientActivity;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.BingnewlistBean;
import com.example.myapplication.ShuJu.ClientBean;
import com.google.gson.Gson;

import java.util.List;

public class ClientApter  extends RecyclerView.Adapter<ClientApter.MyHolder>{
    private Context context;
    private List<ClientBean.RowsBean> list;

    public ClientApter(Context context, List<ClientBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ClientApter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_clientcardt,null);
        return new ClientApter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ClientApter.MyHolder holder, int position) {
        holder.re_clientcardName.setText("名字: "+list.get(position).getName());
        if(!TextUtils.isEmpty(list.get(position).getSex())){
            if(list.get(position).getSex().equals("0")){
                holder.re_clientcardSex.setText("性别: "+"男");
            }else if(list.get(position).getSex().equals("1")) {
                holder.re_clientcardSex.setText("性别: "+"女");
            }
        }
        holder.re_clientcaraddrid.setText("地址:"+list.get(position).getAddress());
        //修改信息
        holder.re_clientcardCenPen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ModifyclientActivity.class);
                Gson gson = new Gson();
                String bean = gson.toJson(list.get(position));
                intent.putExtra("ClientBeanID",bean);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView re_clientcardImg;
        TextView re_clientcardName;
        TextView re_clientcardSex;
        TextView re_clientcaraddrid;
        RelativeLayout re_clientcardCenPen;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            re_clientcardImg = itemView.findViewById(R.id.re_clientcardImg);
            re_clientcardName = itemView.findViewById(R.id.re_clientcardName);
            re_clientcardSex = itemView.findViewById(R.id.re_clientcardSex);
            re_clientcaraddrid = itemView.findViewById(R.id.re_clientcaraddrid);
            re_clientcardCenPen = itemView.findViewById(R.id.re_clientcardCenPen);
        }
    }
}



